<?php
require_once('libraryfiles/config.php');
$content = 'pharmacylist.php';
require_once TMP_USER_PATH;
	$rowsPerPage = isset($_GET['num'])?$_GET['num']:'10';

	if((isset($_GET['PharId']) && (int)$_GET['PharId'] > 0)){
		$changePro = $_GET['PharId'];
		$sql2 = " WHERE p.province_id = $changePro";
		$qstring = "PharId=$changePro";
	} 
	else {
		$changePro = 0;
		$sql2  = '';
		$qstring = '';
	}	
	$provincelist = getProvinceName($changePro);

	/*$select = mysql_query("SELECT * FROM tblpharmacy $sql2 ORDER BY pharmacy_name");*/
	$query ="SELECT p.pharmacy_id,p.pharmacy_image,p.address,p.pharmacy_name,p.phone,p.fax,p.province_id, v.province_id,l.location_name FROM tblpharmacy p LEFT JOIN tblprovince v ON p.province_id = v.province_id LEFT JOIN tbllocation l ON v.province_id = l.province_id $sql2 ORDER BY pharmacy_name";
	$select = mysql_query(getPagingQuery($query, $rowsPerPage));
	$pagingLink = getPagingLink($query, $rowsPerPage, $qstring);
	
?>
<script>
	function viewProvince(){
		with(window.document.frmpamacy){
			if(province.selectedIndex == 0){
				window.location.href = 'pharmacylist.php';
			}
			else {
				window.location.href = 'pharmacylist.php?PharId=' + province.options[province.selectedIndex].value;
			}
		}
	}
</script>
<div class="row">
	<div class="box">
        <div class="title">Pharmacy List</div>
        <table width="568">
            <tr>
                <td colspan="2">
                    <form method="post" name="frmpamacy" action="#">
                    <div style="float:right; padding:10px;">
                    View by province : 	<select name="province" id="province" onChange="viewProvince();">
                            <option value="0">Select Province</option>
                            <?php
                            $sql_pro = "SELECT * FROM tblprovince ORDER BY province_ordering";
                            $result_pro = mysql_query($sql_pro);
                            while($row_pro = mysql_fetch_assoc($result_pro)){
                            ?>
                            <option value="<?php echo $row_pro['province_id']?>" <?php echo($row_pro['province_id']==$changePro)?' selected="selected"':'' ?>><?php echo $row_pro['province_name']?></option>
                            <?php
                            }
                            ?>
                        </select>
                    </div>
                    </form>
                </td>
            </tr>
            <?php 
            if(dbNumRows($select)){
            while($row=mysql_fetch_assoc($select)){?>
            <tr>
                <td width="120">
                    <?php if($row['pharmacy_image']!=""){?>
                    <img src="<?php echo W_ROOT;?>/upload/<?php echo $row['pharmacy_image'];?>" class="border" />
                    <?php 
                    }else{
                    ?> 
                    <img src="<?php echo W_S_IMAGES_DIR;?>no-image-small.png" />
                    <?php } ?> 		
                  </td>
                <td style="padding:10px;" align="left">
                    <div class="pharmacy_name">
                        <strong>
                        <a href="pharmacydetail.php?pharmacy_id=<?php echo $row['pharmacy_id'] ?>">		                   <?php echo $row['pharmacy_name']; ?>
                        </a>
                        </strong>
                    </div>
                    <div style="line-height:20px;">
                        <div style="float:left; line-height:20px;">Address:&nbsp;</div>
                        <div><?php echo $row['address']; ?></div>
                    </div>
                    <div style="line-height:20px;">
                        <div style="float:left;line-height:20px;">Tel:&nbsp;</div>
                        <div>
                            <?php echo $row['phone']; ?>&nbsp;/&nbsp;Fax:&nbsp;<?php echo $row['fax'] ?>
                        </div>
                    </div>
                     <div style="line-height:20px;">
                        <div style="float:left;line-height:20px;">Location:&nbsp;</div>
                        <div>
                            <?php echo $row['location_name']; ?>
                        </div>
                    </div>
                </td>
            </tr>
            <tr><td colspan="2" background="images/line_product_list.jpg" height="0px"></td></tr>
            <?php 
            } // end while
            }else{
            ?>
            <tr>
            <td colspan="2" align="center"><h3 align="center">No Pharmacy in this province!</h3></td>
            </tr>
            <?php
            } // end if
            
            ?>
        </table>
        
	</div><!--<div class="box">-->
</div><!--<div class="row">-->
   
<div class="row">
	<div class="box" style="padding-top:15px;">
			<div class="wp-pagenavi">
				<?php echo $pagingLink;?>
                <div class="clear"></div>
			</div>       
        
	</div><!--<div class="box">-->
</div><!--<div class="row">-->        
	        